package com.ruoyi.web.controller.oto;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.oto.domain.DemandsRecord;
import com.ruoyi.oto.domain.DemandsReply;
import com.ruoyi.oto.domain.dto.CheckDemandsDTO;
import com.ruoyi.oto.domain.dto.DemandsQuryDTO;
import com.ruoyi.oto.domain.dto.ReplyDemandsDTO;
import com.ruoyi.oto.domain.dto.YsReplyDemandsDTO;
import com.ruoyi.oto.domain.vo.DemandsDepartDetailVO;
import com.ruoyi.oto.domain.vo.DemandsDepartVO;
import com.ruoyi.oto.service.DemandsRecordService;
import com.ruoyi.system.service.ISysDeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * 后台-诉求管理器
 */
@RestController
@RequestMapping("/adm/demands")
public class DemandsController extends BaseController{

    @Autowired
    private ISysDeptService sysDeptService;

    @Autowired
    private DemandsRecordService demandsRecordService;

    /**
     * 后台获取要审核的诉求列表-分状态
     * @param demandsQuryDTO
     * @return
     */
    @PostMapping("listCheckDemands")
    public AjaxResult<IPage<DemandsRecord>> listCheckDemands(@RequestBody @Validated DemandsQuryDTO demandsQuryDTO){
        Long deptId = this.getLoginUser().getDeptId();  //部门ID
        IPage<DemandsRecord> result  = demandsRecordService.listCheckDemands(deptId,demandsQuryDTO);
        return AjaxResult.success(result);
    }

    /**
     * 职能部门账号审核诉求
     * @param checkDemandsDTO
     * @return
     */
    @PostMapping ("checkDemands")
    public AjaxResult<Long> checkDemands(@Validated @RequestBody CheckDemandsDTO checkDemandsDTO){
        Long demandsId = demandsRecordService.checkDemands(this.getLoginUser(),checkDemandsDTO);
        return AjaxResult.success(demandsId);
    }

    /**
     * 后台获取诉求列表-只有监管账号可以使用-分状态  admin使用
     * @param demandsQuryDTO
     * @return
     */
    @PostMapping("listDemands")
    public AjaxResult<IPage<DemandsRecord>> listDemands(@RequestBody @Validated DemandsQuryDTO demandsQuryDTO){
        IPage<DemandsRecord> result  = demandsRecordService.listDemandsBack(this.getLoginUser(),demandsQuryDTO);
        return AjaxResult.success(result);
    }

    /**
     * 后台获取诉求列表的受理情况列表 admin使用
     * @param demandId 诉求ID
     * @return
     */
    @GetMapping("listDemandsDepartById/{demandId}")
    public AjaxResult<List<DemandsDepartVO>> listDemandsDepartById(@PathVariable Long demandId){
        List<DemandsDepartVO> result  = demandsRecordService.listDemandsDepartById(this.getLoginUser(),demandId);
        return AjaxResult.success(result);
    }

    /**
     * 后台获取诉处置列表-分状态
     * @param demandsQuryDTO
     * @return
     */
    @PostMapping("listDemandsDepart")
    public AjaxResult<IPage<DemandsDepartVO>> listDemandsDepart(@RequestBody @Valid DemandsQuryDTO demandsQuryDTO){
        IPage<DemandsDepartVO> result  = demandsRecordService.listDemandsDepart(this.getLoginUser(),demandsQuryDTO);
        return AjaxResult.success(result);
    }

    /**
     * 后台获取诉处置的答复列表
     * @param acceptId
     * @return
     */
    @PostMapping("listDemandsDepartReply/{acceptId}")
    public AjaxResult<DemandsDepartDetailVO> listDemandsDepartReply(@PathVariable("acceptId") Long acceptId){
        DemandsDepartDetailVO detail = demandsRecordService.listDemandsDepartReply(acceptId);
        return AjaxResult.success(detail);
    }

    /**
     *  部门人员答复诉求
     * @param replyDemandsDTO
     * @return
     */
    @PostMapping("replyDemandsBack")
    public AjaxResult<DemandsReply> replyDemandsBack(@Validated @RequestBody ReplyDemandsDTO replyDemandsDTO){
       DemandsReply reply = demandsRecordService.replyDemandsBack(this.getLoginUser(),replyDemandsDTO);
       return  AjaxResult.success(reply);
    }

    /**
     *  营商中心介入审核
     * @param ysReplyDemandsDTO
     * @return
     */
    @PostMapping("ysCheckDemandDepart")
    public AjaxResult<DemandsReply> ysCheckDemandDepart(@Validated @RequestBody YsReplyDemandsDTO ysReplyDemandsDTO){
        DemandsReply reply = demandsRecordService.ysReplyDemandsBack(this.getLoginUser(),ysReplyDemandsDTO);
        return  AjaxResult.success(reply);
    }

}
